package com.fulin.jdk8.optional;

import java.util.Optional;

/**
*
* @description 
* @auther fulin16@crnet.com.hk
* @since 2019年2月27日 上午10:26:09
*
*/
public class Client {
	public static void main(String[] args) {
		Insurance insurance = new Insurance("golf");
//		Car car = new Car(insurance);
		Car car = null;
		Person p = new Person(car);
		Optional<Person> person = Optional.of(p);
		Optional<String> name = person.map(Person::getCar).map(Car::getInsurance).map(Insurance::getName);
		System.out.println(name.orElse("other"));
		
		person.flatMap(x -> Optional.of(x.getCar()));		
	}
}
